#include <iostream>
using namespace std;

#define MAXLENGTH 100
int listLength  = 0;
int seqlist[MAXLENGTH+1];

int error=0;

int AddToTail(int data)
{
    if(listLength>MAXLENGTH)
    {
        return -2;//插入错误
    }
    seqlist[listLength++]=data;//填充数据

    return 0;
}

int SearchSeqList(int n)
{
    if(n>MAXLENGTH||n<1||listLength==0)
    {
        return -1;
    }

    return seqlist[n-1];
}

int InsertSeqList(int data,int pos)
{
    pos=pos-1;
    if(pos>MAXLENGTH||pos<1||listLength==0)
    {
        return -1;
    }

    for(int i=listLength+1;i>pos;i--)
    {
        seqlist[i]=seqlist[i-1];
    }

    seqlist[pos]=data;
    listLength++;

    return 0;
}

int DeleteSeqList(int pos)
{
    pos=pos-1;
    if(pos>MAXLENGTH||pos<1||listLength==0)
    {
        return -1;
    }

    for(int i=pos; i<listLength;i++)
    {
        seqlist[i]=seqlist[i+1];
    }
    seqlist[listLength]=0;
    listLength--;

    return 0;
}

void ListPrint(void)
{
    for (int i = 0; i < listLength; i++)
    {
        cout<<seqlist[i]<<" ";  
    }
    cout<<endl;
}

int showListData(int pos)
{
    if(pos==0||pos>MAXLENGTH)
    {
        return -1;
    }

    cout<<seqlist[pos-1]<<endl;
    return 0;
}


int main(int argc,char** argv)
{
    //创建序列表
    AddToTail(2);
    AddToTail(4);
    AddToTail(3);
    AddToTail(5);
    AddToTail(7);
    ListPrint();

    //查询数据
    showListData(4);

    //插入数据
    InsertSeqList(9,2);
    ListPrint();

    //删除数据
    DeleteSeqList(3);
    ListPrint();
    
    return 0;
}